package com.ljw.spring.annotation.test;

import com.ljw.spring.annotation.conf.ConfigOfBeanLifeCycle;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @FileName IOCTest_BeanLifeCycle
 * @Description TODO
 * @Author ljw
 * @Date 2021/2/2 11:46
 * @Version 1.0
 */
public class IOCTest_BeanLifeCycle {

    @Test
    public void test01(){
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConfigOfBeanLifeCycle.class);
        System.out.println("所有bean实例创建完成");
        //获取在IOC容器中注册的所有实例对象
        String[] beanNames = context.getBeanDefinitionNames();
        for (String beanName : beanNames) {
            System.out.println("ioc容器中的bean："+beanName);
        }

        //容器关闭时调用bean的销毁方法
        context.close();
    }
}
